<template>
  <div
    class="tabs_box"
    :style="{
      width: typeof width === 'string' ? width : width + 'px',
      height: typeof height === 'string' ? height : height + 'px',
    }"
  >
    <div
      @click="changeTab(tab)"
      class="tabs_item"
      :class="{
        tabs_item_active: modelValue == tab.value,
      }"
      v-for="(tab, index) in tabList"
      :key="index"
    >
      {{ tab.label }}
    </div>
  </div>
  <common-underline></common-underline>
</template>

<script lang="ts" setup>
  interface Props {
    width?: string;
    height?: string;
    modelValue?: string | number;
    tabList?: TabItem[];
  }
  const props = withDefaults(defineProps<Props>(), {
    width: '100%',
    height: '48px',
    modelValue: 1,
    tabList: () => [],
  });

  const emit = defineEmits({
    change: (tab: TabItem) => tab,
    'update:modelValue': (modelValue: string | number) => modelValue,
  });
  function changeTab(tab: TabItem) {
    emit('update:modelValue', tab.value);
    emit('change', tab);
  }
</script>

<style scoped lang="scss">
  .tabs_box {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    .tabs_item {
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      font-size: 16px;
      padding: 0 10px;
      margin-right: 20px;
      white-space: nowrap;
      position: relative;
      &:hover {
        //   background-color:rgba(85, 85, 86, 0.38);
      }
      &_active {
        color: $primary-color;
        &::after {
          content: '';
          position: absolute;
          left: 0;
          width: calc(100% - 20px);
          height: 2px;
          box-sizing: border-box;
          margin: 0 10px;
          background: #5542f6;
          bottom: 0;
        }
      }
    }
    div:last-child {
      margin-right: 0;
    }
  }
</style>
